package com.tomkk.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

/**
 * Created by Tomkk on 2016/5/21.
 */
public class MysqlConnector {
    private Connection connection;
    private String driver;
    private String url;
    private String user;
    private String pass;
    public Connection getConnection(){
        Properties props = new Properties();
        try {
            //部署的时候不能用绝对路径
//            props.load(new FileInputStream("F:\\workplace\\java\\webFinal\\mysql.ini"));
            driver = "com.mysql.jdbc.Driver";
            url = "jdbc:mysql://localhost:3306/webfinal?useUnicode=true&useSSL=true&characterEncoding=utf8";
            user = "root";
            pass = "root";
            Class.forName(driver);
            connection = DriverManager.getConnection(url,user,pass);

        } catch (ClassNotFoundException e){
            System.out.println("找不到驱动");
            e.printStackTrace();
        } catch (SQLException e) {
            System.out.println("链接数据库失败");
            e.printStackTrace();
        }
        return connection;
    }
}
